﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：QuartzJobListener.cs
// 功能描述：TongTongMall.Quartz
// 
// Create User：jym 2017/02/16
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using Castle.Core.Logging;
using Quartz;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TongTongMall.Quartz.Quartz
{
    public class QuartzJobListener : IJobListener
    {
        public string Name { get; } = "JobListener";

        public ILogger Logger { get; set; }

        public QuartzJobListener()
        {
            Logger = NullLogger.Instance;
        }

        public virtual void JobExecutionVetoed(IJobExecutionContext context)
        {
            Logger.Info($"正在执行 {context.JobDetail.JobType.Name}_{context.JobDetail.Description} ...");
        }

        public virtual void JobToBeExecuted(IJobExecutionContext context)
        {
            Logger.Debug($"Job {context.JobDetail.JobType.Name}_{context.JobDetail.Description} 执行中...");
        }

        public virtual void JobWasExecuted(IJobExecutionContext context, JobExecutionException jobException)
        {
            if (jobException == null)
            {
                Logger.Debug($"Job {context.JobDetail.JobType.Name}_{context.JobDetail.Description} 执行成功.");
            }
            else
            {
                Logger.Error($"Job {context.JobDetail.JobType.Name}_{context.JobDetail.Description} 执行错误， 错误原因: {jobException}");
            }
        }
    }
}
